package study.datastructure.order.recursion;/**
 * @program: datastructure
 * @author: lcy
 * @create: 2024-10-02 21:21
 */

import java.util.LinkedList;
import java.util.Random;

/**
 2024/10/2,
 */

//汉诺塔
public class HanoiTower {
    static LinkedList<Integer> a=new LinkedList<>();
    static LinkedList<Integer> b=new LinkedList<>();
    static LinkedList<Integer> c=new LinkedList<>();

    public static void init(int n){
        for (int i = n; i >=1; i--) {
            a.addLast(i);
        }
    }
    public void test(){
        Random rand=new Random(10);
        int c = rand.nextInt(10) + 'a';
        switch (c) {
            case 'b':
                System.out.println();break;
            case 'c':
                System.out.println('c');break;
            default:
                System.out.println("none");
        }
    }

    /**
     * 多路递归 汉诺塔
     * @param n 盘子总数
     * @param a 源柱子
     * @param b 借柱子
     * @param c 目标柱子
     */
    public static void move(int n,LinkedList<Integer> a,LinkedList<Integer> b,LinkedList<Integer> c){
        if (n == 0) return;
        move(n-1,a,c,b);
        c.addLast(a.removeLast());
        println();
        move(n-1,b,a,c);
    }

    public static void main(String[] args) {
        init(3);
        println();
        move(a.size(),a,b,c);
    }

    private static void println() {
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println("-------------------------");
    }


}
